/**sunday
 */

// 引用axios
import axios from 'axios'

// let url = ''
// if (process.env.NODE_ENV === 'hj4'){
//   url = 'http://www.chinafs.net:8080/'
// }else if(process.env.NODE_ENV === 'hj3'){
//   url = 'http://www.qikan28.com:8080'
// }else if(process.env.NODE_ENV === 'hj2'){
//   url = 'http://yinduxiaofei.com:8080'
// }else if(process.env.NODE_ENV === 'hj1'){
//   url = 'http://kuangxiangshid.com'
// }else if(process.env.NODE_ENV === 'test'){
//   url = 'http://13.251.70.125:8080/'
// }
const requ = axios.create({
  // baseURL: process.env.BASE_API, // api的base_url
  // baseURL: 'http://13.251.70.125:8080/', // api的base_url
  // baseURL: 'http://kuangxiangshid.com',
  // baseURL: 'http://yinduxiaofei.com:8080',
  // baseURL: 'http://www.qikan28.com:8080',
  baseURL: 'http://www.chinafs.net:8080/',
  // baseURL: url,
  timeout: 30000 // 请求超时时间
})
// requ.options.credentials = true
// const p = '%5Baid%3AC4%3AAB%3AB2%3A78%3A92%3A7A%5D,%5Bcode%3ACN%5D,%5Blan%3Azh%5D,%5Bsvc%3A23%5D,%5Bsvn%3A6.0.1%5D,%5Bcvn%3A4.2.1%5D,%5Bcvc%3A2000%5D,%5Bchn%3Abay_test1%5D,%5Bpkg%3Acom.opera.peony%5D'
export function setRequestHaeder(data){
  requ.interceptors.request.use(config => {
    config.headers['X-AUTH-USER'] = data.user_id || data.userid
    config.headers['X-AUTH-TOKEN'] = data.token
    if(config.params){
      config.params.p = data.p
    } else {
      config.params = {p: data.p}
    }
    return config
  }, error => {
    Promise.reject(error)
  })
}

export function getpayInfo(params) {
  return requ.get('/api/pay/status/', {params})
    .then(function (response) {
      return response.data
    })
}

export function submitAppeal(data) {
  return requ.post('api/appeal/submit/', data)
    .then(function (response) {
      return response.data
    })
}

export function getQiniuUploadToken(url, data) {
  return requ.post(url, data)
    .then(function (response) {
      return response.data
    })
}

export function qiniuUpload(data) {
  return requ.post(`http://up-z2.qiniup.com/`, data)
    .then(function (response) {
      return response.data
    })
}

export function getappealList(params) {
  return requ.get('/api/appeal/status/', {params})
    .then(function (response) {
      return response.data
    })
}
